package threading;

public class demo4 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
           while (!Thread.currentThread().isInterrupted()){
               System.out.println("hello thread!");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
//                   e.getStackTrace();
//                   [方式一:立即结束线程]
                   break;
//                   [方式二:什么都不做，不理会]

//                   [方式三:线程稍后处理]
//                   Thread.sleep(1000);
//                   break;
               }
           }
            System.out.println("t线程执行完了");
        });
        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.getStackTrace();
        }

        t.interrupt();
        System.out.println("让t线程中断！");
    }
}
